package top.lshaci.learning.alibaba.cloud.sentinel.hello.config;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * HelloSentinelConfig
 *
 * @author lshaci
 * @since 1.0.0
 */
@Configuration
public class HelloSentinelConfig {

    @Bean
    public BlockExceptionHandler blockExceptionHandler() {
        return (request, response, e) -> {
            response.addHeader("Content-Type", "application/json;charset=utf-8");
            response.getWriter().write("{\"message\":\"请求流量过大\",\"code\":50101}");
        };
    }
}
